//---------------------------------------------------------------------------

#ifndef uEtatH
#define uEtatH
    #include "uFncGdi.h"
    #include "EtatTypes.h"
//---------------------------------------------------------------------------
    #define MODULE_TAG_ETAT         0
    #define MODULE_TAG_DOCUMENT     1
    #define MODULE_TAG_COMPOSANT    2
    #define MODULE_TAG_DESSIN       3
    #define MODULE_TAG_PDF          4
    #define MODULE_TAG_RTF          5
    #define MODULE_TAG_ReOLECB      6
    #define MODULE_TAG_VISUALISE    7
    #define MODULE_TAG_MESSAGE      8
    #define MODULE_TAG_FORMULE      9
    #define MODULE_TAG_PRINTER      10
    #define MODULE_TAG_CALEXMAKER   11
    #define MODULE_TAG_FNCGDI       12
    #define MODULE_TAG_ABOUT        13
    #define MODULE_TAG_SEL_PRINTER  14
    #define MODULE_TAG_CERFA        15
    #define MODULE_TAG_DIVERS       16
    #define MODULE_TAG_STYLES       17
    #define MODULE_TAG_PARAMETRAGE  18

#ifdef _ETAT_DLL
  #define ETATAPI __declspec(dllexport)
#else
  #define ETATAPI __declspec(dllimport)
#endif
    #include "eic.h"
    #include "s:\packages\GED\envoiGED.h"

    class TEICPrinter;
    class CRtf;

    void __fastcall InitDCEcran( );
    void __fastcall DestroyDCEcran( );

    void ETATAPI EtatInitialize(bool bVersionDeDemonstration = false, bool GestionEnvoiGED = true);
    void ETATAPI EtatUnInitialize();

    bool __fastcall PushResolutionAndPutEcran();
    bool __fastcall PopResolution();
    bool __fastcall IsPushedResolution();
    typedef void __cdecl( *TYPE_TRACEF)( EICTag Tag, const char* szFormat, ...);
    enum OLEMethode {OLE_IViewObject2=0, OLE_IViewObject, OLE_IDataObject_EMF, OLE_IDataObject_WMF, OLE_IDataObject_GDI, OLE_Min = OLE_IViewObject2,OLE_Max = OLE_IDataObject_GDI};

    typedef struct{
        short        cptInit;
        int          nRectifPourDessin;
        double       ResolutionX, OldResolutionX, ResolutionY, OldResolutionY;
        TEICPrinter *EICPrinter, *OldEICPrinter;
        AnsiString   SessionName;
        HDC          hDCEcran;
        bool         bVersionDeDemonstration;
        bool         bConception;
        int          LargBarreGauchePixels;
        char*        ficTrace;
        AnsiString   asD_NS;
        HANDLE       hThread;
        bool         LanceEnConception;
        AnsiString   CurrentDir;
        char*        szTempPath;
        HRGN         hRgnTmp1,hRgnTmp2;
        TYPE_TRACEF  TraceF;
        bool         AutoriseTextParBmp;
        OLEMethode   OLETabMethode[OLE_Max+1];
        bool         SortieTextesVerticauxParBmp;
        CRtf        *Rtf;
        double       ResolEcran;
        int          OLEInitialise;
    } CGlobal;
    void InitReg( bool bEcriture);
    void __cdecl TRACEF_Vide( EICTag Tag, const char* szFormat, ...);
    void __cdecl TRACEF_OK( EICTag Tag, const char* szFormat, ...);
    void OLEInitialize();
    void OLEUnInitialize();

#ifdef _ETAT_DLL
    #define TRACEF Glob->TraceF
#else
    #define TRACEF 
#endif
    extern CGlobal ETATAPI *Glob;

    class MyCBarre : public CBarre
    {
    private:	// Déclarations utilisateur
        TDateTime    TimeDebut;
    public:		// Déclarations utilisateur
        virtual __fastcall ~MyCBarre();
        __fastcall MyCBarre(const AnsiString &asMsg, bool bAnnule = true);
        __property  Messages;

    };
    class EAnnulationImpression : public EAbort
    {
        public  :
            __fastcall EAnnulationImpression():EAbort("Annulation de l'impression"){};
    };
    class ETropDeColonnes : public EAbort
    {
        public  :
            __fastcall ETropDeColonnes():EAbort("La totalité des colonnes ne peuvent être incluses dans l'état. Veuillez modifier votre affichage."){};
    };
    #define CATCH_EXCEPTION( tag)                           \
        catch( Exception &ex)                               \
        {   TRACEF( tag, "Exception : \"%s.\"",             \
               			  ex.Message.c_str());              \
            EICDisplayException( tag, ex); }                \
        catch( ...)                                         \
        {   TRACEF( tag, "Exception Non Geree");            \
            DisplayExceptionNonGeree( tag, EmptyStr); }
    #define CATCH_EXCEPTIONc( tag, code)                    \
        catch( Exception &ex)                               \
        {   TRACEF( tag, "Exception : \"%s.\"",             \
               			  ex.Message.c_str());              \
            EICDisplayException( tag, ex); code }           \
        catch( ...)                                         \
        {   TRACEF( tag, "Exception Non Geree");            \
            DisplayExceptionNonGeree( tag, EmptyStr); }
    #define CATCH_Annul_TropDeCol_Abort( )                  \
        catch( EAnnulationImpression &e){throw;}            \
        catch( ETropDeColonnes &e){throw;}                  \
        catch( EAbort &e){throw;}                           \


    void ETATAPI DisplayExceptionNonGeree( EICTag tag, const AnsiString &s);

    void ETATAPI __fastcall DestroyLstStylesModif( TStringList *pLstStylesModif);


    bool IsValeurSignificative( const AnsiString &s);
    bool IsValeurSignificative( double d);
    void TraiteLastError(EICTag TAG, const AnsiString &s);
    #define ChkOLE( Tag, cond)    { int nRet = cond; if( nRet != S_OK) {SetLastError( nRet); AfficheLastErrorT( AnsiString("TAG[")+TAG_MODULE( Tag)+"-"+ TAG_TAG( Tag)+"] "+ #cond);}}

    #include "uDivers.h"
    //---------------------------------------------------------------------------

#endif
